//
//  NSString+HNSURLEncodedAdditions.m
//  HNAiFramework
//
//  Created by tan_xin on 13-7-1.
//  Copyright (c) 2013年 eKing Technology. All rights reserved.
//

#import "NSString+HNSURLEncodedAdditions.h"

@implementation NSString (HNSURLEncodedAdditions)

- (NSString *)urlEncodedFormStringUsingEncoding:(NSStringEncoding)encoding {
    NSString *escapedStringWithSpaces =
    [self percentEscapedStringWithEncoding:encoding
                      additionalCharacters:@"&=+"
                         ignoredCharacters:nil];
    return escapedStringWithSpaces;
}

- (NSString *)percentEscapedStringWithEncoding:(NSStringEncoding)encoding
                          additionalCharacters:(NSString *)add
                             ignoredCharacters:(NSString *)ignoredCharacters {
    CFStringEncoding convertedEncoding = CFStringConvertNSStringEncodingToEncoding(encoding);
    return [(NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                kCFAllocatorDefault,
                                                                (CFStringRef)self,
                                                                (CFStringRef)ignoredCharacters,
                                                                (CFStringRef)add,
                                                                convertedEncoding) autorelease];
}

@end
